/*
 * =====================================================================================
 *
 *       Filename:  Stack.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  11/09/2012 11:46:37 AM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  Kjeldahl (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#include "Stack.h"

Stack * initStack(){
	Stack *S=malloc(sizeof(Stack));	
	memset(S->data,0,sizeof(elmType)*SIZE);
	S->top=-1;
	return S;
}

int emptyStack(Stack *S){
	memset(S->data,0,sizeof(elmType)*SIZE);
	S->top=-1;
	return 0;
}
int destroyStack(Stack *S){
	free(S);
	return 0;

}
int push(Stack *S,elmType value){
	if(S->top==SIZE-1){
	printf("Please resize the Stack\n");
	}else{
	S->top++;
	S->data[S->top]=value;
	}
	return 0;
}
elmType pop(Stack *S){	
	elmType value;

	if(S->top == -1){
		printf("The Stack is empty\n");
	}else{
		value=S->data[S->top];
		S->top--;
	}
	return value;

}
void showStack(Stack *S){
	if(isempty(S)){
		printf("The Stack is empty\n");
	}else{	
		int i=S->top;
		printf("Top\n");
		for(;i>-1;i--){
			printf("%d:%d\n",i,S->data[i]);
		}
		printf("Bottom\n");
	}	

}

bool isempty(Stack *S){
	if(S->top==-1){
		return true;
	}else{
		return false;
	}

}

int getLength(Stack *S){
	return S->top+1;
}

elmTYpe getTop(Stack *S){
	if(! isempty()){
		return S->data[S->top];
	}else{
		printf("The Stack is empty\n");
	}
}


